<template>
  <el-container direction="vertical" style="margin: 20px;">
    <el-header>
      <h1>试卷创编</h1>
    </el-header>
    <el-main>
      <el-form :model="paperForm" label-width="100px">
        <el-form-item label="试卷名称">
          <el-input v-model="paperForm.name" />
        </el-form-item>
        <el-form-item label="试卷编号">
          <el-input v-model="paperForm.number" />
        </el-form-item>
        <el-form-item label="创建者名称">
          <el-input v-model="paperForm.creator" />
        </el-form-item>
        <el-form-item label="创建日期">
          <el-input v-model="paperForm.createDate" readonly />
        </el-form-item>
        <el-form-item label="试卷状态">
          <el-select v-model="paperForm.status" placeholder="请选择">
            <el-option label="草稿" value="draft" />
            <el-option label="待审核" value="pending" />
            <el-option label="已发布" value="published" />
          </el-select>
        </el-form-item>
      </el-form>

      <h2>试题编辑</h2>
      <el-button type="primary" @click="openQuestionBank">添加题目</el-button>
      <el-table :data="paperForm.questions" style="width: 100%">
        <el-table-column prop="type" label="题目类型" />
        <el-table-column prop="content" label="题目内容" />
        <el-table-column label="操作">
          <template slot-scope="scope">
            <el-button size="mini" type="danger" @click="deleteQuestion(scope.$index)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>

      <h2>试卷属性设置</h2>
      <el-form :model="paperForm" label-width="100px">
        <el-form-item label="试卷时限">
          <el-input v-model="paperForm.timeLimit" />
        </el-form-item>
        <el-form-item label="试卷总分">
          <el-input v-model="paperForm.totalScore" />
        </el-form-item>
        <el-form-item label="每题分数">
          <el-input v-model="paperForm.scorePerQuestion" />
        </el-form-item>
      </el-form>

      <el-button type="info" @click="saveDraft">保存为草稿</el-button>
      <el-button type="success" @click="publishPaper">发布试卷</el-button>
      <el-button type="warning" @click="previewPaper">预览试卷</el-button>
    </el-main>
  </el-container>
</template>

<script>
export default {
  data() {
    return {
      paperForm: {
        name: '',
        number: '',
        creator: '',
        createDate: this.getCurrentDate(),
        status: 'draft',
        questions: [],
        timeLimit: '',
        totalScore: '',
        scorePerQuestion: ''
      }
    }
  },
  methods: {
    getCurrentDate() {
      const today = new Date()
      return `${today.getFullYear()}-${today.getMonth() + 1}-${today.getDate()}`
    },
    openQuestionBank() {
      // 打开题库选择题目，这里可以添加弹窗或其他逻辑
    },
    deleteQuestion(index) {
      this.paperForm.questions.splice(index, 1)
    },
    saveDraft() {
      // 保存为草稿的逻辑
      console.log('保存为草稿', this.paperForm)
    },
    publishPaper() {
      // 发布试卷的逻辑
      console.log('发布试卷', this.paperForm)
    },
    previewPaper() {
      // 预览试卷的逻辑
      console.log('预览试卷', this.paperForm)
    }
  }
}
</script>

<style>
/* 在这里添加一些自定义样式 */
</style>
